package com.sskj.cndragon.http;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.cndragon.bean.AddressBean;
import com.sskj.cndragon.bean.AssetBean;
import com.sskj.cndragon.bean.AssetListBean;
import com.sskj.cndragon.bean.AwardBean;
import com.sskj.cndragon.bean.AwardNoticeBean;
import com.sskj.cndragon.bean.BankInfoBean;
import com.sskj.cndragon.bean.CodeUrlBean;
import com.sskj.cndragon.bean.DragonBean;
import com.sskj.cndragon.bean.IncomesBean;
import com.sskj.cndragon.bean.LastTimeBean;
import com.sskj.cndragon.bean.MyIncomeBean;
import com.sskj.cndragon.bean.MyTeamListBean;
import com.sskj.cndragon.bean.NoticeBean;
import com.sskj.cndragon.bean.OrderBuyListBean;
import com.sskj.cndragon.bean.OrderPositionListBean;
import com.sskj.cndragon.bean.OrderSellListBean;
import com.sskj.cndragon.bean.PayWayBean;
import com.sskj.cndragon.bean.RateBean;
import com.sskj.cndragon.bean.RecordListBean;
import com.sskj.cndragon.bean.RushDragonBean;
import com.sskj.cndragon.bean.ShaiTuListBean;
import com.sskj.cndragon.bean.TurntableBean;
import com.sskj.cndragon.bean.UpdataBean;
import com.sskj.cndragon.bean.WithDrawBean;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.UserData;

import java.io.File;
import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {

    public PostRequest<HttpData> register(String mobile, String code, String md5Value, String invitationCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/register")
                .params("tel", mobile)
                .params("code", code)
                .params("pswd", md5Value)
                .params("invitationCode", invitationCode);

    }

    public GetRequest<HttpData> getCode(String tel, int codeType) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + "/dragon/app/user/getTelCode")
                .params("tel", tel)
                .params("codeType", codeType);
    }

    public PostRequest<HttpData> findPwd(String mobile, String mobileCode, String md5Value) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/rewNewPwd")
                .params("tel", mobile)
                .params("code", mobileCode)
                .params("pswd", md5Value);
    }

    public PostRequest<HttpData<UserData>> login(String mobile, String md5Value) {
        return OkGo.<HttpData<UserData>>post(HttpConfig.BASE_URL + "/dragon/app/user/userLogin")
                .params("tel", mobile)
                .params("systemType", "ANDROID")
                .params("pswd", md5Value);
    }

    public GetRequest<HttpData<AssetBean>> getAsset(int userId) {
        return OkGo.<HttpData<AssetBean>>get(HttpConfig.BASE_URL + "/dragon/app/user/userFund")
                .params("stockUserId", userId);
    }

    public GetRequest<HttpData<List<DragonBean>>> getDragons() {
        return OkGo.<HttpData<List<DragonBean>>>get(HttpConfig.BASE_URL + "/dragon/app/index/listInfo");
    }

    public GetRequest<HttpData<DragonBean>> getDragonMsg(String id) {
        return OkGo.<HttpData<DragonBean>>get(HttpConfig.BASE_URL + "/dragon/app/index/oneInfo")
                .params("id", id);
    }

    public PostRequest<HttpData> editNickName(String id, String nickName) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/editUserInfo")
                .params("id", id)
                .params("nickname", nickName);
    }

    public GetRequest<HttpData<List<AddressBean>>> getAddresses(String userID) {
        return OkGo.<HttpData<List<AddressBean>>>get(HttpConfig.BASE_URL + "/dragon/app/user/addressList")
                .params("stockUserId", userID);
    }

    public PostRequest<HttpData> setAddressDefault(String userId, String addressId) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/defaultAddress")
                .params("stockUserId", userId)
                .params("id", addressId);
    }

    public PostRequest<HttpData<UpdataBean>> updata(String verName) {
        return OkGo.<HttpData<UpdataBean>>post(HttpConfig.BASE_URL + "/dragon/app/appVersion/selectNewAppVersion")
                .params("appType", 2);
    }

    public PostRequest<HttpData> delAddress(String addressId) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/deleteAddress")
                .params("id", addressId);
    }

    public PostRequest<HttpData> addOrEditAddress(String userID,
                                                  String name,
                                                  String mobile,
                                                  String province,
                                                  String city,
                                                  String area,
                                                  String detail,
                                                  String type,
                                                  String addressId) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/addAddress")
                .params("stockUserId", userID)
                .params("name", name)
                .params("tel", mobile)
                .params("province", province)
                .params("city", city)
                .params("area", area)
                .params("detailAddress", detail)
                .params("type", type)
                .params("id", addressId);
    }

    public PostRequest<HttpData> editHeadImg(String userID, String imgurl) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/editUserInfo")
                .params("id", userID)
                .params("headUrl", imgurl);
    }

    public PostRequest<HttpData<String>> uploadFile(File file) {
        return OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + "/common/file/upImg").
                params("file", file);
    }

    public PostRequest<HttpData> payPwd(String mobile, String mobileCode, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/setTradePswd")
                .params("tel", mobile)
                .params("code", mobileCode)
                .params("tradePwd", pwd);
    }

    public PostRequest<HttpData> huazhuan(String userID, String amount, String md5Value) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/transfer")
                .params("id", userID)
                .params("num", amount)
                .params("tradePwd", md5Value);
    }

    public PostRequest<HttpData<RecordListBean>> getTransferRecord(String userID, int page, int type) {
        return OkGo.<HttpData<RecordListBean>>post(HttpConfig.BASE_URL + "/dragon/app/user/transferHistory")
                .params("id", userID)
                .params("page", page)
                .params("pageSize", 10)
                .params("type", type);

    }

    public GetRequest<HttpData<UserData>> checkUserMsg(String userMobile) {
        return OkGo.<HttpData<UserData>>get(HttpConfig.BASE_URL + "/dragon/app/user/selectGiveOther")
                .params("tel", userMobile);
    }

    public PostRequest<HttpData> sendCrystal(String userId, String num, String tel, String tradePed) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/transferCrystal")
                .params("id", userId)
                .params("num", num)
                .params("tel", tel)
                .params("tradePwd", tradePed);
    }

    public PostRequest<HttpData<AssetListBean>> getAssetRecord(String userID, int type, int page) {
        return OkGo.<HttpData<AssetListBean>>post(HttpConfig.BASE_URL + "/dragon/app/user/userFundList")
                .params("stockUserId", userID)
                .params("page", page)
                .params("pageSize", 10)
                .params("coinType", type);
    }

    public GetRequest<HttpData<IncomesBean>> getIncomes(String userID) {
        return OkGo.<HttpData<IncomesBean>>get(HttpConfig.BASE_URL + "/dragon/app/user/myPromotion")
                .params("id", userID);
    }

    public PostRequest<HttpData<MyTeamListBean>> getMyTeamRecord(String userID, int type, int page) {
        return OkGo.<HttpData<MyTeamListBean>>post(HttpConfig.BASE_URL + "/dragon/app/user/myTeam")
                .params("id", userID)
                .params("type", type)
                .params("pageSize", 10)
                .params("page", page);
    }

    public GetRequest<HttpData<CodeUrlBean>> getCodeUrl(String userID) {
        return OkGo.<HttpData<CodeUrlBean>>get(HttpConfig.BASE_URL + "/dragon/app/user/getCodeUrl")
                .params("id", userID);
    }

    public PostRequest<HttpData<List<MyIncomeBean>>> getMyIncomeRecord(String userID, String typeID) {
        return OkGo.<HttpData<List<MyIncomeBean>>>post(HttpConfig.BASE_URL + "/dragon/app/user/firstPromotion")
                .params("id", userID)
                .params("type", typeID);
    }

    public PostRequest<HttpData<OrderBuyListBean>> getOrderBuyRecord(String userID, int page) {
        return OkGo.<HttpData<OrderBuyListBean>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getBuyBillList")
                .params("stockUserId", userID)
                .params("pageSize", 10)
                .params("page", page);
    }

    public PostRequest<HttpData<OrderPositionListBean>> getOrderPositionRecord(String userID, int page) {
        return OkGo.<HttpData<OrderPositionListBean>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getHoldList")
                .params("stockUserId", userID)
                .params("pageSize", 10)
                .params("page", page);
    }


    public PostRequest<HttpData<OrderSellListBean>> getOrderSellRecord(String userID, int page) {
        return OkGo.<HttpData<OrderSellListBean>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getSellBillList")
                .params("stockUserId", userID)
                .params("pageSize", 10)
                .params("page", page);
    }

    public PostRequest<HttpData<OrderBuyListBean.OrderBuyBean>> getOrderDetail(String orderID) {
        return OkGo.<HttpData<OrderBuyListBean.OrderBuyBean>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getBillById")
                .params("id", orderID);
    }

    public PostRequest<HttpData> reservationDragon(String dragonID, String userID) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/index/subscribe")
                .params("id", dragonID)
                .params("stockUserId", userID);
    }

    public PostRequest<HttpData<RushDragonBean>> buyDragon(String dragonID, String userID) {
        return OkGo.<HttpData<RushDragonBean>>post(HttpConfig.BASE_URL + "/dragon/app/index/rushDragon")
                .params("id", dragonID)
                .params("stockUserId", userID);
    }

    public GetRequest<HttpData<List<NoticeBean>>> getNotices() {
        return OkGo.<HttpData<List<NoticeBean>>>get(HttpConfig.BASE_URL + "/dragon/app/user/contentNotice");
    }

    public PostRequest<HttpData<List<TurntableBean>>> getTableDatas() {
        return OkGo.<HttpData<List<TurntableBean>>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/getPrizeList");
    }

    public PostRequest<HttpData<String>> getTicketsCount(String userID) {
        return OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/userLotteryDrawNum")
                .params("stockUserId", userID);
    }

    public PostRequest<HttpData<List<AwardBean>>> getAwardRecord(String userID) {
        return OkGo.<HttpData<List<AwardBean>>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/getUserPrizeList")
                .params("stockUserId", userID);
    }

    public PostRequest<HttpData> shaiTu(String userID, String imageUrl) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/userPicture")
                .params("stockUserId", userID)
                .params("imgUrl", imageUrl);
    }

    public PostRequest<HttpData<ShaiTuListBean>> getShaiTuRecord(String userID, int page) {
        return OkGo.<HttpData<ShaiTuListBean>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/userPictureList")
                .params("stockUserId", userID)
                .params("pageSize", 10)
                .params("page", page);
    }

    public PostRequest<HttpData<TurntableBean>> chouJiang(String userID) {
        return OkGo.<HttpData<TurntableBean>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/getUserWinPrize")
                .params("stockUserId", userID);
    }

    public PostRequest<HttpData> uploadPayImg(String orderID, String img) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/saveBuyImg")
                .params("id", orderID)
                .params("payImgUrl", img);
    }

    public PostRequest<HttpData> markPay(String orderID) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/changeBuyStatus")
                .params("id", orderID);
    }

    public PostRequest<HttpData<List<OrderSellListBean.OrderSellBean>>> getOrderSellSplitRecord(String orderID) {
        return OkGo.<HttpData<List<OrderSellListBean.OrderSellBean>>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getSellCfList")
                .params("id", orderID);
    }

    public PostRequest<HttpData<OrderBuyListBean.OrderBuyBean>> getSellDetailMsg(String pollID, String orderID) {
        return OkGo.<HttpData<OrderBuyListBean.OrderBuyBean>>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/getSellBillDetail")
                .params("poolId", pollID)
                .params("swiftNo", orderID);
    }

    public PostRequest<HttpData<LastTimeBean>> getLastTime() {
        return OkGo.<HttpData<LastTimeBean>>post(HttpConfig.BASE_URL + "/dragon/app/index/lastTime");
    }

    public PostRequest<HttpData> timeOut(String orderID) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/index/cancleOrder")
                .params("id", orderID);
    }

    public PostRequest<HttpData> shensu(String sellStockUserId, String buyStockUserId, String swiftNo, String msg, String orderID) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/appeal")
                .params("appealId", sellStockUserId)
                .params("complaintId", buyStockUserId)
                .params("entrustNo", swiftNo)
                .params("type", 1)
                .params("reason", msg)
                .params("billId", orderID);
    }

    public PostRequest<HttpData> confirmPay(String orderID) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/stockBill/changeSellStatus")
                .params("id", orderID);

    }

    public PostRequest<HttpData<List<AwardNoticeBean>>> getAwardList() {
        return OkGo.<HttpData<List<AwardNoticeBean>>>post(HttpConfig.BASE_URL + "/dragon/app/userPrize/getAllUserPrizeList");
    }

    public PostRequest<HttpData<RateBean>> getCrystalRate() {
        return OkGo.<HttpData<RateBean>>post(HttpConfig.BASE_URL + "/dragon/app/user/rmbCrystalRate");
    }

    public GetRequest<HttpData<BankInfoBean>> getBankInfo() {
        return OkGo.get(HttpConfig.BASE_URL + "/dragon/app/user/findSysBank");
    }

    public PostRequest<HttpData> recharge(String userID, String num, String fee, String mImagePath) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/dragon/app/user/recharge")
                .params("id", userID)
                .params("num", num)
                .params("fee", fee)
                .params("url", mImagePath);
    }

    public GetRequest<HttpData> setShouKuanWay(String id, String type, String account, String mImagePath, String paypwd) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.ADD_PAY_WAY)
                .params("stockUserId", id)
                .params("type", type)
                .params("url", mImagePath)
                .params("tradePwd", paypwd)
                .params("account", account);
    }

    public GetRequest<HttpData<PayWayBean>> getPayWay(String id) {
        return OkGo.<HttpData<PayWayBean>>get(HttpConfig.BASE_URL + "/dragon/app/user/selectPayWay")
                .params("type", 1)
                .params("stockUserId", id);
    }

    public GetRequest<HttpData> changeLock(String id, String type, String status) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + "/dragon/app/user/updatePayStatus")
                .params("stockUserId", id)
                .params("type", type)
                .params("status", status);
    }

    /**
     * 提现卖龙
     *
     * @param userID   用户id
     * @param dragonID 龙id
     * @param cny      人民币价格
     * @param paypwd   交易密码
     * @return
     */
    public PostRequest<HttpData> withDraw(String userID, String dragonID, String cny, String paypwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITH_DRAW)
                .params("stockUserId", userID)
                .params("stockId", dragonID)
                .params("buyPrice", cny)
                .params("tradePwd", paypwd);

    }

    /**
     * 凤凰币、汇率、龙列表
     *
     * @param uid 用户ID
     * @return
     */
    public PostRequest<HttpData<WithDrawBean>> getWithdrawPre(String uid) {
        return OkGo.<HttpData<WithDrawBean>>post(HttpConfig.BASE_URL + HttpConfig.WITH_DRAW_PRE)
                .params("id", uid);
    }
}